package com.kwedding.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.kwedding.dto.web.RequestWebAddUser;
import com.kwedding.dto.web.RequestWebGetUserList;
import com.kwedding.dto.web.RequestWebInsertPermission;
import com.kwedding.dto.web.RequestWebLogin;
import com.kwedding.dto.web.RequestWebPermissionByUserId;
import com.kwedding.dto.web.RequestWebPermissionList;
import com.kwedding.dto.web.RequestWebUpdateUser;
import com.kwedding.dto.web.ResponseWebLogin;
import com.kwedding.dto.web.ResponseWebPermissionByUserId;
import com.kwedding.dto.web.ResponseWebPermissionList;
import com.kwedding.dto.web.ResponseWebPermissionSimpleList;
import com.kwedding.dto.web.ResponseWebUserList;
import com.kwedding.service.web.WebUserService;
import com.kwedding.util.BackJson;
import com.kwedding.util.JsonBack;
import com.kwedding.util.JsonBackBase;
import com.kwedding.util.LoggerParent;
import com.kwedding.util.Resp_PageInfo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Controller
@RequestMapping("/rest/web/user")
@Api(tags = "Web-用户")
public class WebUserController extends LoggerParent {

	@Autowired
	private WebUserService webUserService;

	@ApiOperation("获取权限列表")
	@ResponseBody
	@RequestMapping(value = "getAllPermission", method = { RequestMethod.POST })
	private JsonBackBase<Resp_PageInfo<ResponseWebPermissionList>> getAllPermission(
			@RequestBody RequestWebPermissionList webPermissionList) {
		return BackJson.successObj(webUserService.getAllPermission(webPermissionList));
	}

	@ApiOperation("添加权限")
	@ResponseBody
	@RequestMapping(value = "inserPermission", method = { RequestMethod.POST })
	private JsonBackBase inserPermission(@RequestBody RequestWebInsertPermission insertPermission) {
		webUserService.inserPermission(insertPermission);
		return BackJson.success();
	}

	@ApiOperation("后台用户登录")
	@ResponseBody
	@RequestMapping(value = "login", method = { RequestMethod.POST })
	private JsonBackBase<ResponseWebLogin> login(@RequestBody RequestWebLogin webLogin) {
		return BackJson.successObj(webUserService.login(webLogin));
	}

	@ApiOperation("后台用户获取权限")
	@ResponseBody
	@RequestMapping(value = "getPermissionByUserId", method = { RequestMethod.POST })
	private JsonBackBase<List<ResponseWebPermissionByUserId>> getPermissionByUserId(
			@RequestBody RequestWebPermissionByUserId permissionByUserId) {
		return BackJson.successObj(webUserService.getPermissionByUserId(permissionByUserId));
	}

	@ApiOperation("添加用户时获取可用权限列表")
	@ResponseBody
	@RequestMapping(value = "getPermissionList", method = { RequestMethod.POST })
	private JsonBackBase<List<ResponseWebPermissionSimpleList>> getPermissionList() {
		return BackJson.successObj(webUserService.getPermissionList());
	}

	@ApiOperation("添加后台用户")
	@ResponseBody
	@RequestMapping(value = "insertUser", method = { RequestMethod.POST })
	private JsonBackBase insertUser(@RequestBody RequestWebAddUser addUser) {
		webUserService.insertUser(addUser);
		return BackJson.success();
	}

	@ApiOperation("后台用户列表")
	@ResponseBody
	@RequestMapping(value = "getUserList", method = { RequestMethod.POST })
	private JsonBackBase<Resp_PageInfo<ResponseWebUserList>> getUserList(
			@RequestBody RequestWebGetUserList getUserList) {
		return BackJson.successObj(webUserService.getUserList(getUserList));
	}

	@ApiOperation("修改用户信息")
	@ResponseBody
	@RequestMapping(value = "updateUser", method = { RequestMethod.POST })
	private JsonBackBase updateUser(@RequestBody RequestWebUpdateUser updateUser) {
		webUserService.updateUser(updateUser);
		return BackJson.success();
	}
}
